#ifndef JIT_H
#define	JIT_H

#include "../BMC.h"
#include "../HMC.h"
#include "../Context/ExeContext.h"

#ifdef	__cplusplus
extern "C" {
#endif
  
//IMPORTANT: The functions commented out below were experimental functions
//used to try to implement code generation using the LLVM backend API.
//This was not used because LLVM didn't cope well with some of the stuff
//that was used for code generation. LLVM was scrapped and we decided to use
//gcc as our backend.
    
//This function pipes to clang and returns a bit-code version of the module. 
//NOTE: This function actually returns a pointer to a llvm::Module. This is
//necessary, since this code is called from C code.
//void* JIT_CompileToIRModule(char* BlockCode);

//This function links the IRModule from the current BMC to the 6502 pre-compiled
//instruction library.
//void* JIT_LinkIRModuleToRuntime(void* IRModule);

//This function compiles the context code into bitcode and links it to the 
//current IRModule
//void* JIT_LinkIRModuleToContext(void* IRModule, char* ContextCode);

//This function is responsible for invoking the JIT compiler itself. It receives
//an IRModule as input, and generates native machine code for it.
//HMC* JIT_GetHMC(void* IRModule, uint16_t Addr);

typedef enum JITCFlags{
    JITCF_PIPE = 0x01
}JITCFlags;
    
//This function must be called once to initialize the JIT infrastructure.
void JIT_Init(void);

//This function is used to compile a block's representation in C code

//The following comment is not up to date. I'll leave it here for reference.
//This is used for the representation that uses pre-compiled
//versions of the instructions which are linked into the module for Code
//and inlined as LTO.
void JIT_CompileBlockF(char* Code, BMC* Block, uint32_t Flags);

void JIT_CompileBlockOPT(char* Code, BMC* Block, uint32_t Flags, ExeContext* Context);

HMC* JIT_DynamicLink(char* Filename, char* FunctionName);

char* JIT_GetDynLibName(BMC* Block, const char* Prefix, const char* Suffix, uint64_t ContextHash);

#ifdef __cplusplus
}
#endif

#endif	/* JIT_H */

